﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.Windows.Resources;
using System.Collections.Generic;
using WeatherCN_Phone.Models;
using System.IO;

namespace WeatherCN_Phone.Infrastructure
{
    //读取城市名与城市编码映射关系的处理器
    public static class CityIDMappingProcessor
    {
        public static List<CityIDMapping> GetCityIDMappingList()
        {
            StreamResourceInfo r = Application.GetResourceStream(new Uri("Assets/CityID.txt", UriKind.Relative));
            using (StreamReader reader = new StreamReader(r.Stream))
            {
                string CurrentLineStr = string.Empty;
                string ScopeName = string.Empty;
                List<CityIDMapping> ListCity = new List<CityIDMapping>();

                while ((CurrentLineStr = reader.ReadLine()) != null)
                {
                    if (CurrentLineStr.IndexOf('=') != -1)
                    {
                        ListCity.Add(new CityIDMapping { Scope = ScopeName, CityID = CurrentLineStr.Split(new char[] { '=' })[0], CityName = CurrentLineStr.Split(new char[] { '=' })[1] });
                    }
                    else
                    {
                        ScopeName = CurrentLineStr;
                    }
                }

                return ListCity;

            }
        }
    }
}
